﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using wdss.WebServices;

namespace wdss.GUI
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
            Response.Expires = -1500;
            Response.CacheControl = "no-cache";
            
        }

        protected void fetch_btn_Click(object sender, EventArgs e)
        {
            FetchUserID(emailID.Text);
            if ((int)Session["userid"] != 0)
                Server.Transfer("~/GUI/SendNewPassword.aspx");
            else
                Server.Transfer("~/GUI/Login.aspx");
        }
        private void FetchUserID(string username)
        {
            LogService logService = new LogService();
            UserTransferObject user = new UserTransferObject();
            NewPasswordService newPassword = new NewPasswordService();
            user = newPassword.GetNewPassword(username);
            if(user.userid != 0)
            {
               
                Session.Add("userid", user.userid);
                Session.Add("username", user.username);
                Session.Add("question", user.question);
                Session.Add("role", user.role);
                
            }
            else
            {
                HttpContext.Current.Response.Write("<script>alert('User Doesn't Exist!! ')</script>");
               // Response.Write("<script language=javascript>window.location.href='" + Request.Url.ToString() + "'</script>");
                //Server.Transfer("~/GUI/Login.aspx");
            }
        }
    }
}
